//
//  Header_type2_TableViewCell.swift
//  Pods
//
//  Created by eme on 2017/4/1.
//
//

import UIKit

class Header_type2_TableViewCell: UITableViewCell {
    
    @IBOutlet weak var Statusheader_Icon: UIImageView!      //订单状态图标
    
    @IBOutlet weak var status_Label: UILabel!               //订单状态
    
    @IBOutlet weak var timeRemaining_Label: UILabel!        //剩余时间
    
    var timer = Timer()
    var countdownType = 2
    var customDate:(hour:Int,minute:Int,second:Int) = (0,0,0)
    var orderType:String?
    var payid:String?
    var orderid:String?
    var changeOrderStatus:Change_OrderStatus?
    var orderDeatils:OrderDetailsModel?{
        didSet{
            if Int(self.orderDeatils!.orderstatus)! <= 10{
                self.Statusheader_Icon.image = UIImage(named: ["","DFH_Image","DFH_Image","DSH_Image","DSH_Image","complete_image","complete_image","Close_Image","Close_Image","Close_Image","Close_Image"][Int(self.orderDeatils!.orderstatus)!], in: SansaCore.bundle, compatibleWith: nil)
                self.status_Label.text = ["","待发货","待发货","部分发货","已发货","已收货","已完成","已关闭","已关闭","已关闭","已关闭"][Int(self.orderDeatils!.orderstatus)!]
            }
        }
    }

    override func awakeFromNib() {
        super.awakeFromNib()
        status_Label.normal_fontSize(15)
        timeRemaining_Label.normal_fontSize(13)

        timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector:#selector(Header_type2_TableViewCell.timeheader), userInfo: nil, repeats: true)
    }
    func timeheader(){
        
        if self.customDate.hour <= 0 &&  self.customDate.minute <= 0 && self.customDate.second <= 0{
            
            timer.invalidate()
            self.timeRemaining_Label.text = "确认收货剩余时间：\(0)小时\(0)分\(0)秒"
            
        }else{
            if self.customDate.second == 0{
                
                if customDate.minute == 0{
                    
                    customDate.hour -= 1
                    customDate.minute = 59
                    customDate.second = 59
                    
                }else{
                    
                    customDate.minute -= 1
                    customDate.second = 59
                }
                
                
            }else{
                
                customDate.second -= 1
            }
            self.timeRemaining_Label.text = "确认收货剩余时间：\(customDate.hour)小时\(customDate.minute)分\(customDate.second)秒"
        }
    }
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    }

}
